package com.LeeCode;

/**
 * x 的平方根
 */

public class Code069 {
    public static void main(String[] args) {
        System.out.println(new Code069().mySqrt(2147483647));
    }

    public int mySqrt(int x) {
        if (x == 1) return 1;
        int left = 0, right = x;
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if ((long) mid * mid <= x)
                left = mid;
            else
                right = mid;
        }
        return left;
    }
}
